// save ticket mapping
class localStrongHelpObject
{
    getData(issueKey)
    {
        let ticketsAndDeveloperMapping = {};
        try {
            issueKey = this.keyFilter(issueKey);
            ticketsAndDeveloperMapping = this.getTicketsObject();
        } catch (e) {
            alert(e);
        }

        return ticketsAndDeveloperMapping[issueKey] ? ticketsAndDeveloperMapping[issueKey] : '';
    }
    
    setData(issueKey, developer)
    {
        issueKey = this.keyFilter(issueKey);
        let ticketsObject = this.getTicketsObject();
            ticketsObject[issueKey] = developer;
        localStorage.setItem('jira-tickets', JSON.stringify(ticketsObject));
        Logger.debug('set data', ticketsObject);
    }

    getTicketsString()
    {
        let ticketsString = localStorage.getItem('jira-tickets');
        return ticketsString ? ticketsString : '';
    }

    getTicketsObject()
    {
        let ticketsString = this.getTicketsString();
        if (ticketsString) {
            ticketsString = JSON.parse(ticketsString);
        } else {
            ticketsString = {};
        }

        return ticketsString;
    }

    keyFilter(key)
    {
        let config = this.getConfig();
        Logger.debug('ingore string:', config.ignoreString);
        if (config.ignoreString) {
            key = key.replace(config.ignoreString, '');
            Logger.debug('filter key', key);
        }

        return key;
    }

    getConfig(key)
    {
        if (!key) {
            key = 'config';
        }
        return JSON.parse(localStorage.getItem(key));
    }

    addConfig(key, value)
    {
        let config = this.getConfig();
        config[key] = value;
        localStorage.setItem('config', JSON.stringify(config));
        return this.getConfig();
    }

    setConfig(data)
    {
        localStorage.setItem('config', JSON.stringify(data));
    }
}
var dataObject = new localStrongHelpObject();